// mine/pages/animation/demo10/index.ts
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		swiperList: [{
			type: 'image',
			url: 'https://img1.baidu.com/it/u=833508245,4122008499&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=313',
			mLeft: 0,
			zIndex: 0
		}, {
			type: 'image',
			url: 'https://img1.baidu.com/it/u=833508245,4122008499&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=313',
			mLeft: 0,
			zIndex: 0
		}, {
			type: 'video',
			url: 'https://vd4.bdstatic.com/mda-ndjbhv5d9k8qpepw/sc/cae_h264_delogo/1650444501967507992/mda-ndjbhv5d9k8qpepw.mp4?v_from_s=hkapp-haokan-hbe&auth_key=1692592305-0-0-169aa26e1b439ac0432e327da7a17dd7&bcevod_channel=searchbox_feed&pd=1&cr=2&cd=0&pt=3&logid=1905826674&vid=5609614002569628168&klogid=1905826674&abtest=111803_3-112162_2-112345_1',
			mLeft: 0,
			zIndex: 0
		}, {
			type: 'image',
			url: 'https://img0.baidu.com/it/u=2788559078,1468722098&fm=253&fmt=auto&app=120&f=JPEG?w=1422&h=800',
			mLeft: 0,
			zIndex: 0
		}, {
			type: 'image',
			url: 'https://img0.baidu.com/it/u=2788559078,1468722098&fm=253&fmt=auto&app=120&f=JPEG?w=1422&h=800',
			mLeft: 0,
			zIndex: 0
		}, {
			type: 'image',
			url: 'https://img0.baidu.com/it/u=2788559078,1468722098&fm=253&fmt=auto&app=120&f=JPEG?w=1422&h=800',
			mLeft: 0,
			zIndex: 0
		},],
		touchStart: 0,
		direction: '',
	},
	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad() {
		this.touchSwiper()
	},

	// 初始化swiper
	touchSwiper() {
		let list = this.data.swiperList;
		list.map((item: any, index: number) => {
			item.zIndex = list.length / 2 + 1 - Math.abs(index - list.length / 2);
			item.mLeft = index - list.length / 2;
		})
		this.setData({
			swiperList: list
		})
		console.log(this.data.swiperList)
	},

	touchStart(e: any) {
		this.setData({
			touchStart: e.touches[0].pageX
		})
	},
	touchMove(e: any) {
		this.setData({
			direction: e.touches[0].pageX - this.data.touchStart > 0 ? 'right' : 'left'
		})
	},
	// 计算滚动
	touchEnd(e: any) {
		let direction = this.data.direction;
		let list = this.data.swiperList;
		if (direction == 'right') {
			let mLeft = list[0].mLeft;
			let zIndex = list[0].zIndex;
			for (let i = 1; i < list.length; i++) {
				list[i - 1].mLeft = list[i].mLeft;
				list[i - 1].zIndex = list[i].zIndex;
			}
			// 最后一个到第一个位置，循环
			list[list.length - 1].mLeft = mLeft
			list[list.length - 1].zIndex = zIndex
			this.setData({
				swiperList: list
			})
			console.log(this.data.swiperList)
		} else {
			let mLeft = list[list.length - 1].mLeft;
			let zIndex = list[list.length - 1].zIndex;
			for (let i = list.length - 1; i > 0; i--) {
				list[i].mLeft = list[i - 1].mLeft;
				list[i].zIndex = list[i - 1].zIndex;
			}
			// 最后一个到第一个位置，循环
			list[0].mLeft = mLeft
			list[0].zIndex = zIndex
			this.setData({
				swiperList: list
			})
		}
	},


	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady() {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow() {
		let animation = wx.createAnimation({
			duration: 2000,
			timingFunction: 'linear',
			delay: 500,
		})
		animation.translateY(-253).step()
		animation.translateY(0).step()
		this.setData({
			animation: animation.export()
		})
	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide() {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload() {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh() {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom() {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage() {

	}
})